require(['init'], function () {
 var ue=UE.getEditor('editor');
 var id="";
 var flag=true;
  function Agencyinformation() {
    var $photo = $("#J_img");
    $("input").focus(function(){
      $('#submit_html').attr("disabled",false);
    });
    $('#editor').mousedown(function(){
      $('#submit_html').attr("disabled",false);
    });

    $.ajax({
      url: '/api/page/about/1',
      type: 'get',
      success: function (data) {
        if(data.data.length=0){
          $('#preview').hide();
        }else{
          $('#preview').show();
        }
        $('[name=id]').val(data.data.id)
        $('#J_enroll_submit').attr("disabled","disabled");
        $('[name=title]').val(data.data.title);
        $('[name=description]').val(data.data.description);
        $photo.attr('src', data.data.img);
        //获取附文本编辑器的内容
        ue.ready(function(){
          ue.setContent(data.data.body);
        });
      }
    })
    $("#submit_html").on("click",function(){
        var title=$('[name=title]').val();
        var description=$('[name=description]').val();
        var img = $('#J_uploadCover img').attr('src');
        id=$('[name=id]').val();
        var body=ue.getContent();
        var popUpBox = new PopUpBox({
              type: 'dom',
              style: 'default contentScroll',
              submitBtnType: 'confirm',
              titleText: '温馨提示',
              show: true,
              content: "<div style='margin-left:27px;margin-top:34px;'>确定要保存吗?</div>",
              callback: {
                  yes: function (e) {
                      var arr={
                          title:title,
                          description:description,
                          img:img,
                          body:body
                        }
                      ajaxMethod({
                          url: '/api/page/about/1',
                          data:arr,
                          type: 'put',
                          success:function(data){
                           $('#submit_html').attr("disabled",true);
                          }
                      })
                    }
              },
              position: {
                  width:448,
                  height:226
              }
          })
      })
   //图片上传
   function imgUpload($container) {
       var $uploadCoverBox = $container.find('.icon-uploadimg')
       var $uploadCoverThumb = $uploadCoverBox.find('img')
       var $uploadInput = $uploadCoverBox.find('input')
       var coverUploadInput = new UploadInput({
           $dom: $uploadInput,
           done: function (uploadSrc) {
             console.log(uploadSrc);
             var uploadFullSrc='/api/file?u=' + uploadSrc;
             //var parseSrc = getFileNameByPath(uploadSrc);
             if (uploadSrc) {
               $uploadCoverThumb.attr('src', uploadFullSrc);
               $uploadCoverBox.attr('data-value', uploadFullSrc);
               return;
             }
           }
       });
    }
   imgUpload($('#J_imgupload'));
  }
Agencyinformation();


})
